package mine;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * Created by james on 16/1/28.
 */
public class AnnotationLab {
    public static void main(String[] args) {
        testClazz();
    }

    private static void testClazz() {
        Class<?> clz = null;
        try {
            clz = Class.forName(GoodsBean.class.getName());
            System.out.println(clz.isAnnotationPresent(author.class));
            author au = clz.getAnnotation(author.class);
            System.out.println(au.name() + " " + au.webSite());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    private static void testField(){
        GoodsBean bean = GoodsBean.newInstance();
        Class<? extends GoodsBean> clazz = bean.getClass();
        Field[] arrField = clazz.getDeclaredFields();
        for (Field f:arrField){
            Annotation[] arrAnno = f.getAnnotations();
            System.out.println(arrAnno.length);
            if (f.isAnnotationPresent(unique.class)){
                System.out.println(f.getName() + " annotation:unique");
            } else {
                System.out.println(f.getName() + " annotation:null");
            }
        }
    }
}
